package com.ygsj;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;


public class UpdatePopWindow extends PopupWindow {
    @SuppressLint("InflateParams") //跳过检查
    public UpdatePopWindow(final Activity context) {//realname是为了传递参数使用;

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View view = inflater.inflate(R.layout.pop_success, null);
       // TextView tv_Tag = view.findViewById(R.id.tv_TagWord);
        // 设置SelectPicPopupWindow的View
        this.setContentView(view);
        // 设置SelectPicPopupWindow弹出窗体的宽
//        this.setWidth(LayoutParams.WRAP_CONTENT);
        this.setWidth((int) context.getResources().getDimension(R.dimen.pop_wh));
        // 设置SelectPicPopupWindow弹出窗体的高
//        this.setHeight(LayoutParams.WRAP_CONTENT);
        this.setHeight((int) context.getResources().getDimension(R.dimen.pop_hei));

        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置点击屏幕其它地方弹出框消失
        this.setOutsideTouchable(true);
        // 刷新状态
        this.update();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0000000000);
        // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ，设置其他控件变化等操作;
        //解决点击外部而popwindo无法消失的问题;
        this.setBackgroundDrawable(dw);

        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimationPreview);
        //以下设置点击事件
        // RelativeLayout re_addfriends = (RelativeLayout) view.findViewById(R.id.re_addfriends);
       // TextView tv_detail = view.findViewById(R.id.tv_detail);
       // tv_detail.setText(detailInfo);

    }
    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAtLocation(parent, Gravity.CENTER, 0, 0);

        } else {
            this.dismiss();
        }
    }
}
